// pages/goods_list/goods_list.js
Page({
  data: {
    pagenum: 1,
    pagesize: 10,
    goodsList: [],
    query: '',
    hasMore: false
  },
  onLoad(query) {
    const item = query.query
    this.setData({query: item})
    this.getGoodsList()
  },

  async getGoodsList() {
    const res = await wx.http.get('/api/public/v1/goods/search', {
      query: this.data.query,
      pagenum: this.data.pagenum,
      pagesize: 10
    })
    const goodsList = [...this.data.goodsList, ...res.data.message.goods]
    const pagenum = ++this.data.pagenum
    const hasMore = goodsList.length === res.data.message.total
    this.setData({goodsList})
    this.setData({pagenum})
    this.setData({hasMore})
  },

  onScrollToLower() {
    if (this.data.hasMore) return
    this.getGoodsList()
  }
})